package jin.si.com.suo;

import java.util.HashMap;

/**
 * @description: 消费者
 * @ClassName CilentMyRunnable
 * @Author MT
 * @Date 2021/7/4 15:09
 **/
//消费者
public class CilentMyRunnable implements Runnable{

    private Person p;
    public CilentMyRunnable(Person p){
        this.p=p;
    }

    @Override
    public void run() {
        while (true){
            synchronized (p){
                if(!p.flag){
                    try {
                        p.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(p.getName()+"---"+p.getAge()+"去赚钱");
                p.flag=false;//消费完毕将flag改为false，原因是让生产者生产，消费者等待
                p.notify();//唤醒等待
            }
        }



    }
}
